﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace GtalkBot
{
    public partial class cfg : Form
    {

        INIClass config = new INIClass(Application.StartupPath + "/config.ini");
        public cfg()
        {
            InitializeComponent();
        }

        private void cfg_Load(object sender, EventArgs e)
        {
            autostart.Checked = config.IniReadValue("LoginInfo", "autostart") == "true" ? true : false;
            opencmd.Checked = config.IniReadValue("LoginInfo", "opencmd") == "true" ? true : false;
            autofriend.Checked = config.IniReadValue("LoginInfo", "autofriend") == "true" ? true : false;
            sqlchk.Checked = config.IniReadValue("LoginInfo", "sqlchk") == "true" ? true : false;
            openkey.Checked = config.IniReadValue("LoginInfo", "openkey") == "true" ? true : false;
            AC.Checked = config.IniReadValue("LoginInfo", "AC") == "true" ? true : false;
        }

        private void btnok_Click(object sender, EventArgs e)
        {
            try
            {



                config.IniWriteValue("LoginInfo", "autostart", autostart.Checked ? "true" : "false");

                config.IniWriteValue("LoginInfo", "opencmd", opencmd.Checked ? "true" : "false");

                config.IniWriteValue("LoginInfo", "autofriend", autofriend.Checked ? "true" : "false");

                config.IniWriteValue("LoginInfo", "sqlchk", sqlchk.Checked ? "true" : "false");

                config.IniWriteValue("LoginInfo", "openkey", openkey.Checked ? "true" : "false");

                config.IniWriteValue("LoginInfo", "AC", AC.Checked ? "true" : "false");

                if (autostart.Checked == true)
                {

                    RegistryKey regKey = default(RegistryKey);
                    regKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                    regKey.SetValue(Application.ProductName, Application.ExecutablePath);
                    regKey.Close();
                }
                else
                {

                    RegistryKey regKey = default(RegistryKey);
                    regKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                    regKey.SetValue(Application.ProductName, Application.ExecutablePath);
                    regKey.DeleteValue(Application.ProductName);
                    regKey.Close();
                }
            }
            finally
            {
                this.Close();
            }




        }


    }
}
